package com.inspur.jxpcxt.activitys;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentTransaction;
import android.text.TextUtils;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import com.inspur.jxpcxt.app.JXPCApplication;
import com.inspur.jxpcxt.fragments.RetriveFragment;
import com.inspur.jxpcxt.interfaces.IAsyncLoadListener;
import com.inspur.jxpcxt.utils.NetworkUtils;
import com.inspur.jxpcxt.utils.SendMail;
import com.inspur.jypcxt.R;

public class UnableLoginActivity extends FragmentActivity implements
		OnClickListener {
	// 返回登录界面
	private TextView mBackTv = null;
	// 反馈内容
	private EditText mFeedEdt = null;
	// 回复方式:手机还是qq号码
	private EditText mEmialOrPhone = null;
	// 找回密码
	private Button mRetrievePswdBtn = null;
	private Button mSend = null;

	@Override
	protected void onCreate(@Nullable Bundle arg0)
		{
			super.onCreate(arg0);
			// requestWindowFeature(Window.FEATURE_NO_TITLE);
			setContentView(R.layout.activity_unablelogin);
			JXPCApplication.getInstance().addActivity(UnableLoginActivity.this);

			initUI();
		}

	private void initUI()
		{
			mBackTv = (TextView) findViewById(R.id.btn_nav_back);
			mFeedEdt = (EditText) findViewById(R.id.edt_feed);
			mEmialOrPhone = (EditText) findViewById(R.id.edt_feed_qq_or_phone);
			mSend = (Button) findViewById(R.id.btn_feed_send);
			mRetrievePswdBtn = (Button) findViewById(R.id.btn_retrieve_pswd);

			mBackTv.setOnClickListener(this);
			mSend.setOnClickListener(this);
			mRetrievePswdBtn.setOnClickListener(this);
		}

	@Override
	public void onClick(View v)
		{
			// TODO Auto-generated method stub
			switch (v.getId()) {
			case R.id.btn_nav_back: {
				// 返回登录界面
				finish();
			}
				break;
			case R.id.btn_feed_send: {
				// 一键反馈

				final String message = mFeedEdt.getText().toString();
				final String phoneorqq = mEmialOrPhone.getText().toString();
				if (TextUtils.isEmpty(message)) {
					Toast.makeText(getApplicationContext(), "请输入您宝贵的意见",
							Toast.LENGTH_SHORT).show();
					return;
				}
				if (!NetworkUtils.isConnectInternet(this)) {
					Toast.makeText(this, "网络不可用，请检查网络连接", Toast.LENGTH_SHORT)
							.show();
					return;
				}
				SendMail.sendmail(message + '\n' + "Phone&QQ：" + phoneorqq,
						new IAsyncLoadListener<Void>() {

							@Override
							public void onSuccess(Void t)
								{
									// TODO Auto-generated method stub
									runOnUiThread(new Runnable() {
										public void run()
											{
												Toast.makeText(
														getApplicationContext(),
														"发送成功!!",
														Toast.LENGTH_SHORT)
														.show();
												UnableLoginActivity.this
														.finish();
											}
									});
								}

							@Override
							public void onFailure(String msg)
								{
									// TODO Auto-generated method stub
									runOnUiThread(new Runnable() {
										@Override
										public void run()
											{
												Toast.makeText(
														getApplicationContext(),
														"发送失败!!",
														Toast.LENGTH_SHORT)
														.show();
											}
									});
								}
						});
			}
				break;
			case R.id.btn_retrieve_pswd: {
				// 跳转到找回密码界面
				// 进入播放页面

				// 获取一个fragment事务
				FragmentTransaction transaction = getSupportFragmentManager()
						.beginTransaction();
				//transaction.setCustomAnimations(arg0, arg1)
				// 四个参数：第一个是
				// fragment添加时的动画，第二个是移除时的动画，第三个是添加到后退栈时的动画，第四个是从后退栈移除时的动画
				transaction.setCustomAnimations(R.anim.slide_in_right,
						R.anim.slide_out_right, R.anim.slide_in_right,
						R.anim.slide_out_right);
				// 把fragment添加到布局中
				transaction.add(R.id.pane_content_menu, new RetriveFragment());
				// 添加到后退栈
				transaction.addToBackStack(RetriveFragment.class.getName());
				// 提交事务
				transaction.commit();
			}
				break;
			default:
				break;
			}

		}
}
